package cn.tedu._09interceptor.base.config;

import cn.tedu._09interceptor.base.interceptors.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类
 *
 * WebMvcConfigurer接口中定义了添加拦截器的方法
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    //addI+回车；
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //策略1：拦截所有请求
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/**");
//        //策略2：拦截指定的1个请求，比如 拦截登录请求
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/user/login");
//        策略3：拦截指定的多个请求，比如 拦截登录和注册功能
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/user/login","/v1/user/reg");
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/**");
        //策略4：排除指定的请求，比如 排除登录请求
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/login");



    }
}
